package com.zxy.ziems.server.device.controller;

import com.zxy.ziems.server.device.pojo.dto.ChannelDTO;
import com.zxy.ziems.server.device.pojo.vo.ChannelVO;
import com.zxy.ziems.server.device.service.ChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 采集管理-通讯通道
 * @author 10348359
 * @create 2024-03-25 15:13
 */
@RestController
@Validated
@RequestMapping("/api")
public class ChannelController {
    /**
     * 通信通道新增
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/device/collector/channel/add")
    public void add(@Validated(value = ChannelDTO.Add.class) @RequestBody ChannelDTO dto) throws Exception {
        service.add(dto);
    }

    /**
     * 通信通道更新
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/device/collector/channel/update")
    public void update(@Validated(value = ChannelDTO.Update.class) @RequestBody ChannelDTO dto) throws Exception {
        service.update(dto);
    }

    /**
     * 删除通信通道
     * @param dto 用户post参数
     * @return
     */
    @PostMapping("/device/collector/channel/delete")
    public void delete(@Validated(value = ChannelDTO.Delete.class) @RequestBody ChannelDTO dto) throws Exception {
        service.deleteById(dto.getId());
    }

    /**
     * 通信通道详情
     * @param id id
     * @return
     */
    @GetMapping("/device/collector/channel/detail")
    public ChannelVO detail(String id) throws Exception {
        return service.detailById(id);
    }

    /**
     * 通道列表 详情请求detail
     * @return
     */
    @GetMapping("/device/collector/channel/list")
    public List<ChannelVO> list() throws Exception {
        return service.viewList();
    }


    private ChannelService service;

    @Autowired
    public void setService(ChannelService channelService) {
        this.service = channelService;
    }

}
